package org.bluedream.core.module.dao.bill;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.bluedream.core.module.entity.bill.OrdBody;

import java.util.List;

/**
 * @ClassName OrdBodyDao
 * @Description TODO
 * @Author foxsand
 * @Data OrdBody 9:10
 * @Version
 */
public interface OrdBodyDao extends BaseMapper<OrdBody> {

    @Select("select a.bill_num as billNum , a.code as code, b.barcode as barcode, b.name as name, a.qty as qty ," +
            " a.id as id , a.create_by as createBy , a.create_date as createDate , a.update_by as updateBy , a.update_date as updateDate , a.status as status , a.remarks as remarks , " +
            "   case " +
            "       when mod(a.qty , b.qpc) = 0 then to_char(a.qty / b.qpc)  " +
            "       when mod(a.qty , b.qpc) != 0  and a.qty/b.qpc = 0 then to_char(floor(a.qty/b.qpc))||'+'||to_char(a.qty) " +
            "       when mod(a.qty , b.qpc) != 0  and a.qty/b.qpc != 0 then to_char(floor(a.qty/b.qpc))||'+'||to_char(a.qty - b.qpc) end as qtyStr , " +
            "b.qpc as qpc , b.qpc_str as qpcStr , b.unit as unit , b.spec as spec , a.oprice as oprice , a.total as total " +
            "from ord_body a , depItemUser b " +
            " ${ew.customSqlSegment} and a.code = b.code ")
    IPage<OrdBody> selectPage(IPage<OrdBody> page, @Param("ew") Wrapper<OrdBody> wrapper);
}
